import os
import re
import requests
from requests.api import get, head
from Crypto.Cipher import AES

res = requests.get("https://p1.ocs.hjfile.cn/10002/m3u8/1461478516461471736/raw/7f0d8b38b4f24fb09fce1a3f46c30579.m3u8").text
key = requests.get("https://p1.ocs.hjfile.cn/10002/slice/1461478516461471736/raw/key//7f0d8b38-b4f2-4fb0-9fce-1a3f46c30579.key").content
print(key)
name = "12.2【购物 App】BBCo -  Shopping 2"
ts = re.findall(r"\n(.*?ts)\n",res)
number = 0
for i in ts:
    urls="https://p1.ocs.hjfile.cn"+i
    gets = requests.get(url=urls).content
    cryptor = AES.new(key, AES.MODE_CBC, key)
    with open('./ts/'+str(number)+'.ts',mode="wb") as file:
        file.write(cryptor.decrypt(gets))
    print(str(number)+" 写入成功："+urls)
    number+=1

all_ts = os.listdir('./ts/')
with open('./down/'+name+'.mp4', 'wb+') as file:
    for i in range(len(all_ts)):
        ts_video_path = os.path.join('./ts/', all_ts[i])
        file.write(open(ts_video_path, 'rb').read())
        os.remove(ts_video_path)

print("下载成功...")